package o;

import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class erf {
    private final Map<sa, d> ˋ = new HashMap();
    private final e ˏ = new e();

    static class d {
        final Lock ˎ;
        int ˏ;

        private d() {
            this.ˎ = new ReentrantLock();
        }
    }

    static class e {
        private final Queue<d> ˎ;

        private e() {
            this.ˎ = new ArrayDeque();
        }

        d ॱ() {
            synchronized (this.ˎ) {
                d dVar = (d) this.ˎ.poll();
            }
            if (dVar == null) {
                return new d();
            }
            return dVar;
        }

        void ˏ(d dVar) {
            synchronized (this.ˎ) {
                if (this.ˎ.size() < 10 && !this.ˎ.offer(dVar)) {
                    Logger.ˏ("CacheWriteLocker", "The element was not added to this queue.");
                }
            }
        }
    }

    erf() {
    }

    void ॱ(sa saVar) {
        d dVar;
        synchronized (this) {
            dVar = (d) this.ˋ.get(saVar);
            if (dVar == null) {
                dVar = this.ˏ.ॱ();
                this.ˋ.put(saVar, dVar);
            }
            dVar.ˏ++;
        }
        dVar.ˎ.lock();
    }

    void ˎ(sa saVar) {
        d dVar;
        synchronized (this) {
            dVar = (d) this.ˋ.get(saVar);
            if (dVar == null || dVar.ˏ <= 0) {
                int i;
                StringBuilder append = new StringBuilder().append("Cannot release a lock that is not held, key: ").append(saVar).append(", interestedThreads: ");
                if (dVar == null) {
                    i = 0;
                } else {
                    i = dVar.ˏ;
                }
                throw new IllegalArgumentException(append.append(i).toString());
            }
            int i2 = dVar.ˏ - 1;
            dVar.ˏ = i2;
            if (i2 == 0) {
                d dVar2 = (d) this.ˋ.remove(saVar);
                if (dVar2.equals(dVar)) {
                    this.ˏ.ˏ(dVar2);
                } else {
                    throw new IllegalStateException("Removed the wrong lock, expected to remove: " + dVar + ", but actually removed: " + dVar2 + ", key: " + saVar);
                }
            }
        }
        dVar.ˎ.unlock();
    }
}
